<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;

class Index extends Main
{  
    public function __construct(){
        parent::__construct();
    }
    // public function __construct(){
    //     parent::__construct();
    // }
    /**
     * 首页展示
    */
    public function index()
    {
        return $this->fetch();
    }
    /**
     * 桌面页
    */
    public function welcome()
    {
        //全部工单
        $all_count = Db::name('proinfo')
                ->count();
        //已完成工单
        $finish = Db::name('order')
                ->where('status', 3)
                ->count();

        //未处理工单
        $need = Db::name('order')
        ->group('pId')
        ->where('status', 1)
        ->where('exp', 'one')
        ->count();

        //处理中工单
        $ing = $all_count - $finish - $need;

        //工单完成率
        $rate = round($finish/$all_count*100,2);

        //工单来源：
        $weixin = Db::name('order')
                ->group('pId')  
                ->where('resource', 1)
                ->count();
        $tel = Db::name('order')
                ->group('pId')
                ->where('resource', 2)
                ->count();
        $website = Db::name('order')
                ->group('pId')
                ->where('resource', 3)
                ->count();

        $this->assign('all_count', $all_count);
        $this->assign('finish', $finish);
        $this->assign('ing', $ing);
        $this->assign('need', $need);
        $this->assign('rate', $rate);
        
        $this->assign('weixin', $weixin);
        $this->assign('tel', $tel);
        $this->assign('website', $website);

        return $this->fetch();
    }

    
   
}
